<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 <script>
   $(function() {
   
      /* $('#admin_yhgl_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/userAction!dataGrid.action',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'name',
			sortOrder : 'asc',
			/*pagePosition : 'both', 
			frozenColumns : [ [ {
				field : 'id',
				title : '编号',
				width : 150,
				hidden : true
			}, {
				field : 'name',
				title : '登录名称',
				width : 150,
				sortable : true
			} ] ],
			columns : [ [ {
				field : 'pwd',
				title : '密码',
				width : 150,
				formatter : function(value, row, index) {
					return '<span title="'+row.name + '###' + value+'">' + value + '</span>';
				}
			}, {
				field : 'createdatetime',
				title : '创建时间',
				width : 150,
				sortable : true
			}, {
				field : 'modifydatetime',
				title : '最后修改时间',
				width : 150,
				sortable : true
			} ] ],
			//toolbar : '#admin_yhgl_toolbar'
		}); */
 
   
		 var dataGrid = $('#admin_yhgl_datagrid').datagrid({
			url : 'userAction!dataGrid.action',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'name',
			sortOrder : 'asc',
			checkOnSelect : false,//true:选中行时复选框选中
			selectOnCheck : false,
			// checkOnSelect:selectOnCheck both default true 
			// checkOnSelect:selectOnCheck=false:false 时单击行 不选中即不变色。复选框选中时 行也不变色选中
			// checkOnSelect:selectOnCheck=false:true 选中行时不选中复选框，选中复选框时行选中
			//checkOnSelect:selectOnCheck=true:false 选种行时复选框选中，选中复选框时行不选中
			nowrap : false,
			frozenColumns : [ [ {
				field : 'id',
				title : '编号',
				width : 150,
				checkbox : true
			}, {
				field : 'name',
				title : '登录名称',
				width : 100,
				sortable : true,
				formatter : function(value, row) {
					return  '<span title="'+value+'">'+value+'</span>';
				}
			} ] ],
			columns : [ [ {
				field : 'pwd',
				title : '密码',
				width : 150,
				formatter : function(value, row) {
					return  '*******';
				}
			}, {
				field : 'createdatetime',
				title : '创建时间',
				width : 150,
				sortable : true
			}, {
				field : 'modifydatetime',
				title : '最后修改时间',
				width : 150,
				sortable : true
			},
			{
 				title : '操作',
 				field : 'action',
				width : 150,
				formatter : function(value, row){
				  return '删除             编辑';
				}
			}
			 ] ],
		   // toolbar : '#admin_yhgl_toolbar'
			 
		  toolbar:[{
			   text:'新增',
			   iconCls:'icon-add',
			   handler:function(){
			       $("#admin_yhgl_addForm input").val('');   
			       $("#admin_yhgl_addDialog").dialog('open');//$("#admin_yhgl_addDialog").css('width','200px');
			   
			   }
			 },'-',
			 {
			   text:'删除',
			   iconCls:'icon-remove',
			   handler:function(){
			     
			   delFun();
			   }
			 },'-',
			 {
			   text:'编辑',
			   iconCls:'icon-edit',
			   handler:function(){
			     editFun();
			   }
			 }
			 
			 ],
 		});  
 	$("#admin_yhgl_addDialog").dialog({
 	   title:'添加用户',
 	   modal:true,
 	   closed:true,
  	   buttons:[{
 	      text:'新增',
 	      handler:function(){
 	         $("#admin_yhgl_addForm").form({
 	            url:'userAction!add.action',
 	            success:function(data){     
			 	      var json=jQuery.parseJSON(data);
			 	      if(json.success){
			 	          //$("#admin_yhgl_datagrid").datagrid('load',{});重新加载datagrid
			 	          
			 	          //$("#admin_yhgl_datagrid").datagrid('appendRow',json.obj);//添加到后面
			 	          $("#admin_yhgl_datagrid").datagrid('insertRow',{index:0,row:json.obj});
			 	         $('#admin_yhgl_addDialog').dialog('close');
			 	         
			 	      }
			 	     $.messager.show({
						title:'提示',
						msg:json.msg
			          });
			          
	           } 
   	         });
 	        $("#admin_yhgl_addForm").submit();
 	      }
 	   }]	
 	});
  });
 	
 function editFun(){
   var rows=   $("#admin_yhgl_datagrid").datagrid('getChecked');
   if(rows.length==1){
         var t=$("<div></div>");
	     t.dialog({
	      title:'编辑用户',
	      modal:true,
	      width:500,
	      height:200,
	      href:'${pageContext.request.contextPath}/admin/userEdit1.jsp',
	      buttons:[{
	         text:'确认修改',
	         handler:function(){
	            $('#admin_userEdit_editForm').form('submit',{
	              url:'userAction!edit.action',
	              success:function(data){     
			 	      var json=jQuery.parseJSON(data);
			 	      if(json.success){
 			 	          var index= $("#admin_yhgl_datagrid").datagrid('getRowIndex',rows[0].id);
			 	          $("#admin_yhgl_datagrid").datagrid('updateRow',{index:index,row:json.obj});
			 	          $("#admin_yhgl_datagrid").datagrid('unselectAll');
			 	          t.dialog('close');
			 	      }
			 	     $.messager.show({
						title:'提示',
						msg:json.msg
			          });
	                } 
	            });
 	          }
	      }],
	       onClose:function(){
	         $(this).dialog('destroy');
	       },
	       onLoad:function(){
	         $("#admin_userEdit_editForm").form('load',rows[0]);
	       }
	    });
    }else{
       $.messager.alert('提示','请选择一条记录进行编辑!');
      }
 } 	
 
 function searchFun(){
   $("#admin_yhgl_datagrid").datagrid('load',{
      name:$("#admin_yhgl_search input[name=name]").val()
   });
 }
 function clearFun(){
   $("#admin_yhgl_searchForm input").val('');
   $("#admin_yhgl_datagrid").datagrid('load',{});
 }
 function delFun(){
  var rows = $("#admin_yhgl_datagrid").datagrid('getChecked');
  
 
  if(rows.length>0){
     $.messager.confirm('确认','确认删除选中项目吗?',function(r){
	  if (r){
	    var ids=[];
		  for(var i=0;i<rows.length;i++){
		      ids.push(rows[i].id);
		  }
		  $.ajax({
			     url:'userAction!remove.action',
			     data:{
			       ids:ids.join(',')
			     },
			     dataType:'json',
			     success:function(data){
			         $("#admin_yhgl_datagrid").datagrid('load');
			        $.messager.show({
					       title:'提示',
					       msg:data.msg
		             });
			      }
		   });		 
	     }//end ok
    });//end queren
  }else{
    $.messager.show({
       title:'提示',
       msg:'勾选要删除的行!'
    });
  }   
 }
</script>
<div class="easyui-layout" data-options="fit:true">
   <div id="admin_yhgl_search" data-options="region:'north',title:'查询条件',border:false" style="height:150px">
   
          <form id="admin_yhgl_searchForm" method="post">
				<table class="table table-hover table-condensed" style="display: nones;">
					<tr rowspan="2">
						<th>登录名</th>
						<td><input name="name" placeholder="可以模糊查询登录名" class="span2" /></td>
					</tr>
					<tr rowspan="2">
						<th>创建时间</th>
						<td><input class="span2" name="createdatetimeStart" placeholder="点击选择时间" onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly="readonly" />至<input class="span2" name="createdatetimeEnd" placeholder="点击选择时间" onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly="readonly" /></td>
					</tr>
					<tr rowspan="2">
						<th>最后修改时间</th>
						<td><input class="span2" name="modifydatetimeStart" placeholder="点击选择时间" onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly="readonly" />至<input class="span2" name="modifydatetimeEnd" placeholder="点击选择时间" onclick="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly="readonly" /></td>
					</tr>
					  <tr>
					      <td align="right">
					          <a href="#" class="easyui-linkbutton" data-options=" " onclick="searchFun()">查询</a>
					     </td>
					     <td align="center">
                             <a href="#" class="easyui-linkbutton" data-options="" onclick="clearFun()">清空</a>  
					     </td>
					  </tr>
				</table>
  			</form>

   </div>
   <div data-options="region:'center'" >
       <table class="easyui_datagrid" id="admin_yhgl_datagrid"></table>
   </div>
</div>
<div id="admin_yhgl_addDialog" style="height:150px;width:450px" align="center">
   <form id="admin_yhgl_addForm" method="post">
     <table>
      <tr>
         <td>用户名:</td>
         <td><input name="name"/></td>
         <td>密码:</td>
         <td><input type="password" name="pwd"/></td>
       </tr>
        <tr>
         <td>创建时间:</td>
         <td><input name="createdate" readOnly="readonly"/></td>
         <td>修改时间:</td>
         <td><input name="" readOnly="readonly"/></td>
       </tr>
     </table>
   </form>
</div>

<!-- <div id="admin_yhgl_toolbar">
	 <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" >编辑</a>
     <div class="datagrid-btn-separator"></div>
	 <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-help',plain:true" >帮助</a>
</div>
 -->

